
from flask import Blueprint, request, render_template
from sqlalchemy import desc
from applications.common.utils.rights import authorize
from applications.common.utils.http import table_api, fail_api, success_api


from applications.common.hangingUpCore import executionFlow


'''
主界面
'''
mainView = Blueprint('mainView', __name__, url_prefix='/ye/mainView')



# 初始化任务
@mainView.get('/initTask')
def initTask():
    # 获取请求参数
    # type_name = str_escape(request.args.get('typeName', type=str))
    baseParam = dict(
            intervalSeconds=1, 
            replaceTask=True, 
        )
    opertionParam = dict(
        )
    executionFlow.initTask(baseParam,opertionParam)
    return success_api(msg="任务初始化成功")

# 停止任务
@mainView.get('/stopTask')
def stopTask():
    executionFlow.stopScheduledTask()
    return success_api(msg="任务停止成功")

# 开始任务
@mainView.get('/startTask')
def startTask():
    executionFlow.startScheduledTask()
    return success_api(msg="任务启动成功")

# 删除任务
@mainView.get('/removeTask')
def removeTask():
    executionFlow.removeScheduledTask()
    return success_api(msg="任务删除成功")